package com.hcy.controller.driver;

import com.hcy.driver.DriverPageInfoBz;
import com.hcy.driver.dto.request.BaseInfoRequestDTO;
import com.hcy.driver.dto.response.BaseInfoResponseDTO;
import com.hcy.ordermodel.dto.request.HomeInfoRequestDTO;
import com.hcy.ordermodel.dto.response.HomeInfoResponseDTO;
import com.hcy.rabbitbasicmodel.enums.Code;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author huchenying
 * @Description
 * @Date 2021/12/29 18:06
 */
@RestController
@RequestMapping("/driver")
public class DriverPageInfoController {

    Logger logger = LoggerFactory.getLogger(DriverPageInfoController.class);

    @Autowired
    DriverPageInfoBz driverPageInfoBz;

    @Value("${gaode_config.key}")
    private String key;

    @PostMapping("/homeInfo")
    public ResponseData<HomeInfoResponseDTO> doHomeInfo(@RequestBody @Validated HomeInfoRequestDTO requestDTO){
        logger.info("doHomeInfo start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<HomeInfoResponseDTO> responseData = new ResponseData<>();
        try {
            HomeInfoResponseDTO infoResponseDTO = driverPageInfoBz.doHomeInfo(requestDTO);
            responseData.setCode(Code.Success);
            responseData.setData(infoResponseDTO);
            return responseData;
        } catch (Exception e) {
            logger.error("查询homeInfo失败" + e);
            responseData.setCode(Code.Fail);
            responseData.setMsg("系统异常");
            return responseData;
        }
    }

    /**
     * @Author huchenying
     * @Description 通过登录的手机号获取基本信息
     * @Date  2021/12/30 14:55
     **/
    @PostMapping("/baseInfo")
    public ResponseData<BaseInfoResponseDTO> baseInfo(@RequestBody @Validated BaseInfoRequestDTO requestDTO){
        logger.info("baseInfo start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<BaseInfoResponseDTO> responseData = new ResponseData<>();
        try {
            BaseInfoResponseDTO responseDTO = driverPageInfoBz.getCarInfo(requestDTO);
            responseDTO.setKey(key);
            responseData.setCode(Code.Success);
            responseData.setData(responseDTO);
            return responseData;
        } catch (Exception e) {
            logger.error("查询车辆基础信息错误！",e);
            e.printStackTrace();
            responseData.setCode(Code.Fail);
            responseData.setMsg("系统异常！");
            return responseData;
        }
    }
}
